package com.jiedeng.mapper;

import com.jiedeng.entity.ProjectCorpDetails;
import com.jiedeng.entity.ProjectCount;
import com.jiedeng.entity.ProjectDetails;
import com.jiedeng.mapper.provider.ProjectCountSqlProvider;
import com.jiedeng.model.FileRecord;
import com.jiedeng.model.Project;
import com.jiedeng.model.Task;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author zhouyb
 * @ClassName: ProjectMapper
 * @Description: 项目
 * @date 2018/5/4 9:41
 */
@Mapper
public interface ProjectMapper {
    /**
     * 分页查询首页统计数据
     *
     * @param epsId
     * @param projectName
     * @param status
     * @param page
     * @param pageSize
     * @param corpIds
     * @return
     */

    //@Select(value = "select t.Project_ID ,t.Project_Caption,count(TaskID) checkNum,count(closed_loop) closedLoopNum," +
    //        " count(this_month) thisMonthNum,count(this_season) thisSeasonNum" +
    //        " from(" +
    //        " SELECT tp.Project_ID, tp.Project_Caption, tt.TaskID," +
    //        " CASE WHEN tt.IsCloseDo = 0 THEN tt.TaskID ELSE NULL END closed_loop," +
    //        "  CASE WHEN date_format(tt.Create_Time, '%Y-%m') = date_format(NOW(), '%Y-%m') THEN tt.TaskID ELSE NULL END this_month," +
    //        "  CASE WHEN QUARTER (tt.Create_Time) = QUARTER (now()) THEN tt.TaskID ELSE NULL END this_season" +
    //        " FROM t_project tp LEFT JOIN t_task tt ON tt.Project_ID = tp.Project_ID WHERE tp.EPS_ID = #{epsId} ) t " +
    //        " GROUP BY t.Project_ID,t.Project_Caption")
    @Results({
            @Result(column = "Project_ID", property = "id"),
            @Result(column = "Project_Caption", property = "projectName"),
            @Result(column = "checkNum", property = "checkNum"),
            @Result(column = "closedLoopNum", property = "closedLoopNum"),
            @Result(column = "thisMonthNum", property = "thisMonthNum"),
            @Result(column = "thisSeasonNum", property = "thisSeasonNum")
    })
    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findProjectCountList")
    List<ProjectCount> findProjectCountList(long epsId, String projectName, String status, String page, String pageSize, String corpIds);

    /**
     * 查询统计总数
     *
     * @param epsId
     * @param projectName
     * @param status
     * @param corpIds
     * @return
     */
    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findAllProjectCount")
    int findAllProjectCount(long epsId, String projectName, String status, String corpIds);

    /**
     * 查询照片数据
     *
     * @param projectId
     * @param taskId
     * @param closeDo
     * @return
     */
    @Results({
            @Result(column = "oldphoto_path", property = "oldPhotoPath"),
            @Result(column = "CheckOrClose", property = "checkClose"),
            @Result(column = "Check_ID", property = "checkId"),
            @Result(column = "photo_path", property = "photoPath"),
    })
    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findPhotoCountList")
    List<FileRecord> findPhotoCountList(long projectId, String taskId, int closeDo);

    /**
     * 查询照片总数
     *
     * @param projectId
     * @return
     */
    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findAllphotoCount")
    int findAllphotoCount(@Param("projectId") long projectId);

    /**
     * 查询任务数据
     *
     * @param projectId
     * @param page
     * @param pageSize
     * @return
     */
    @Results({
            @Result(column = "TaskID", property = "id"),
    })
    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findtaskCountList")
    List<Task> findtaskCountList(long projectId, String page, String pageSize);

    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findtaskCountNum")
    int findtaskCountNum(@Param("projectId") long projectId);

    /**
     * 查询单位下所有工程
     *
     * @param projectName
     * @param status
     * @param corpIds
     * @return
     */
    @Results({
            @Result(column = "Project_ID", property = "id"),
            @Result(column = "Project_Caption", property = "caption"),
    })
    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findProjectByCorpIdsSql")
    List<Project> findProjectByCorpIds(String projectName, String status, String corpIds);

    /**
     * 根据项目查询单位
     *
     * @param projectId
     * @return
     */

    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findProjectCorpByProjectIdSql")
    List<ProjectCorpDetails> findProjectCorpByProjectId(@Param("projectId") long projectId);

    /**
     * 根据单位和项目删除项目人员
     *
     * @param projectId
     * @param corpId
     */
    @DeleteProvider(type = ProjectCountSqlProvider.class, method = "deleteProjectPersonByCorpIdAndProjectIdSql")
    void deleteProjectPersonByCorpIdAndProjectId(@Param("corpId") long corpId, @Param("projectId") long projectId);

    /**
     * 根据id查询项目详情
     *
     * @param projectId
     * @return
     */
    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findProjectDetailsByIdSql")
    List<ProjectDetails> findProjectDetailsById(@Param("projectId") long projectId);

    /**
     * 根据id查询项目详情
     *
     * @param corpIds
     * @param personId
     * @return
     */
    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findProjectByCorpIdsAndPersonIdSql")
    List<ProjectDetails> findProjectByCorpIdsAndPersonId(@Param("corpIds") String corpIds, @Param("personId") long personId);

    @SelectProvider(type = ProjectCountSqlProvider.class, method = "findCorpPropAndCorpByProjectIdSql")
    List<Map<String,String>> findCorpPropAndCorpByProjectId( @Param("personId") long projectId);
}
